// pages/my/teacher/setExercise/setExercise.js
const app = getApp()
var base_url = app.globalData.url
Page({

  /**
   * 页面的初始数据
   */
  data: {
    index:0,
    time:'',
    index_msg: 0,
    array_cnt: ['1', '2', '3', '4', '5', '6','7','8','9','10'],
    index_cnt: '',
    index_inp:'',
    index_msg:'',
    index:''

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.getStorage({
      key: 'teacher_id',
      success: function (res) {
        wx.request({
          url: base_url+'/setExerciseData/',
          method: 'POST',
          data: {
            teacher_id: res.data
          },
          header: {
            "Content-Type": "application/x-www-form-urlencoded"
          },
          success: function (res) {
            if (res.data['flag'] == true) {
              that.setData({
                array_msg: res.data['datas'],
                array_class: res.data['classDatas_lst']
              })
            }
          }
        })
      },
    })
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  bindPickerChange:function(e){
    this.setData({
      index:e.detail.value
    })
  },
  bindTimeChange:function(e){
    this.setData({
      time:e.detail.value
    })
  },
  bindPickerMessage: function (e) {
    console.log(e.detail.value)
    this.setData({
      index_msg: e.detail.value
    })
  },
  bindPickerCount:function(e){
    this.setData({
      index_cnt: e.detail.value
    })
  },
  bindInputTeacherPhone:function(e){
    this.setData({
      index_inp: e.detail.value
    })
  },
  gotoSelectWord:function(){
    var that = this;
    console.log(that.data.index_cnt)
    if (that.data.index_inp == ''){
      wx.showModal({
        title: '警告',
        content: '请填写标题',
        showCancel: false,
        confirmText: '确定',
        success: function (res) {
        }
      })
    } else if (that.data.index == '') {
      wx.showModal({
        title: '警告',
        content: '请选择练习班级',
        showCancel: false,
        confirmText: '确定',
        success: function (res) {
        }
      })
    }else if (that.data.time==''){
      wx.showModal({
        title: '警告',
        content: '请选择完成时间',
        showCancel: false,
        confirmText: '确定',
        success: function (res) {
        }
      })
    } else if (that.data.index_msg == '') {
      wx.showModal({
        title: '警告',
        content: '请选择教材信息',
        showCancel: false,
        confirmText: '确定',
        success: function (res) {
        }
      })
    }else if (that.data.index_cnt == ''){
      wx.showModal({
        title: '警告',
        content: '请选择练习遍数',
        showCancel: false,
        confirmText: '确定',
        success: function (res) {
        }
      })
    }else{
      var o = {};
      o.title = that.data.index_inp
      o.className = that.data.array_class[parseInt(that.data.index)]
      o.time = that.data.time
      o.book = that.data.array_msg[parseInt(that.data.index_msg)]
      o.count = that.data.array_cnt[parseInt(that.data.index_cnt)]
      wx.setStorage({
        key: 'exerciseInfo',
        data: o,
        success: function (res) {
          console.log(res)
        }
      })
      wx.navigateTo({
        url: '../selectWord/selectWord',
        success: function (res) {
          console.log(res)
        },
        fail: function () {
        }
      })
    }
    
  }
})